﻿/***********************************************************************
 * <copyright file="SqlServerEmailConfigDao.cs" company="B/S JSC">
 * -->    Copyright (C) statement. All right reserved
 * </copyright>
 * 
 * Created:   Hoang Bich Son 
 * Email:    sonhb@newman.vn
 * Website:
 * Create Date: Friday, March 14, 2014
 * Usage: 
 * 
 * RevisionHistory: 
 * Date         Author               Description 
 * 
 * ************************************************************************/

using System;
using System.Data;
using BusinessSecurity;
using DataObjects;
using DataObjects.ADO;
using DataSecurity.StandartInterfaces;

namespace DataSecurity.ADO.SqlServer.Dictionary
{
    /// <summary>
    /// SqlServerEmailConfig
    /// </summary>
    internal class SqlServerEmailConfigDao : IEmailConfig
    {
        /// <summary>
        /// Gets the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public EmailConfig Get(int id = 0)
        {
            const string sql = @"uspGet_EmailConfig";
            object[] parms = { "@Id", id };
            return Db.Read(sql, CommandType.StoredProcedure, Make, parms);
        }

        /// <summary>
        /// The make
        /// </summary>
        private static readonly Func<IDataReader, EmailConfig> Make = reader =>
          new EmailConfig
          {
              Id = reader["Id"].AsInt(),
              Title = reader["Title"].AsString(),
              EmailAddress = reader["EmailAddress"].AsString(),
              EmailUser = reader["EmailUser"].AsString(),
              Password = reader["Password"].AsString(),
              Host = reader["Host"].AsString(),
              Port = reader["Port"].AsInt(),
              Ssl = reader["SSL"].AsBool(),
              Status = reader["Status"].AsBool()
          };        
    }
}
